<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of async_news
 *
 * @author phuchv
 */
require APPPATH . 'libraries/memcached_client.php';

class async_news extends CI_Controller {
   
    function __construct()  {
		$this->_initdata();
	}

	function _initdata()
	{
		parent::__construct();     
        $this->load->model('Frontendmodel');
        
	}
    
    //update lastest news to memcached
    public function update_lastest_news(){
        if (MEMCACHED_ENABLED == "true"){
            $this->data['aLastestNews'] = $this->Frontendmodel->_get_news_nopaging("news.news_id,news.title,news.short_desc,news.url,news.img_thumb,news.img_thumb2,news.img_thumb3,news.parent_cate_url,news.display_date,news_cate.cate_name,news_cate.url as news_cate_url", "  news.status='1' ", " order by news_id desc ", 0,20);

            $key = LASTEST_NEWS;
            $strSet = base64_encode(serialize($this->data['aLastestNews']));
            memcached_client::cache(CacheModule::LASTEST_NEWS)->set($key, $strSet, false, EXPIRED_LASTEST_NEWS);
        }
    }
    
    //update feature news to memcached
    public function update_feature_news(){
        if (MEMCACHED_ENABLED == "true"){                       
            $strSelect = "news.news_id,news.title,news.short_desc,news.img,news.img_thumb,news.img_thumb2,news.img_thumb3,news.url,news.parent_cate_url,news.parent_cate_url,news_cate.cate_name,news_cate.url as news_cate_url";
            $strWhere = " news.is_hot='1' and news.status='1' and DATEDIFF(CURDATE(),online_date)<=".FEATUREDNEWS_DAYS;
            $strOrderBy = " order by news.online_date desc ";			

            $this->data['aFeatureNews'] = $this->Frontendmodel->_get_news_nopaging($strSelect, $strWhere, $strOrderBy, 0,16);

            $key = FEATURE_NEWS;
            $strSet = base64_encode(serialize($this->data['aFeatureNews']));
            memcached_client::cache(CacheModule::FEATURE_NEWS)->set($key, $strSet, false, EXPIRED_FEATURE_NEWS);
        }
    }
    
    public function set_category_to_cache(){
        if (MEMCACHED_ENABLED == "true"){
            $this->data['aNewsCate'] = $this->Frontendmodel->_get_news_cate_list();

            $key = NEWS_CATE;
            $strSet = base64_encode(serialize($this->data['aNewsCate']));
            memcached_client::cache(CacheModule::NEWS_CATE)->set($key, $strSet, false, EXPIRED_NEWS_CATE);
        }
    }
}

?>
